﻿using System;
using System.IO;

namespace Coding4Fun.BoxingBots.Common
{
	public class GameStatePacket : GamePacket
	{
		public GameState GameState { get; set; }
		public int Robot1Health { get; set; }
		public CalculatedSensorData Robot1SensorData { get; set; }
		public int Robot2Health { get; set; }
		public CalculatedSensorData Robot2SensorData { get; set; }
		public bool LockSkeleton1 { get; set; }
		public bool LockSkeleton2 { get; set; }

		public override void ReadPacket(BinaryReader br)
		{
			GameState = (GameState)br.ReadInt32();
			Robot1Health = br.ReadInt32();
			Robot1SensorData = Robot1SensorData.Read(br);
			Robot2Health = br.ReadInt32();
			Robot2SensorData = Robot2SensorData.Read(br);
			LockSkeleton1 = br.ReadBoolean();
			LockSkeleton2 = br.ReadBoolean();
		}

		public override void WritePacket(BinaryWriter bw)
		{
			bw.Write((int)GameState);
			bw.Write(Robot1Health);
			Robot1SensorData.Write(bw);
			bw.Write(Robot2Health);
			Robot2SensorData.Write(bw);
			bw.Write(LockSkeleton1);
			bw.Write(LockSkeleton2);
		}

		public override string ToString()
		{
			return string.Format(
								"GameState: {0}" + Environment.NewLine +
								"Robot1Health: {1}" + Environment.NewLine +
								"Robot1SensorData: {2}" + Environment.NewLine +
								"Robot2Health: {3}" + Environment.NewLine +
								"Robot2SensorData: {4}" + Environment.NewLine +
								"LockSkeleton1: {5}" + Environment.NewLine +
								"LockSkeleton2: {6}" + Environment.NewLine,
								GameState, Robot1Health, Robot1SensorData, Robot2Health, Robot2SensorData, LockSkeleton1, LockSkeleton2);
		}
	}
}
